package com.ruoyi.business.impl;

import java.util.List;

import com.ruoyi.business.domain.LawyerTime;
import com.ruoyi.business.mapper.LawyerTimeMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.OrderDetailMapper;
import com.ruoyi.business.domain.OrderDetail;
import com.ruoyi.business.service.IOrderDetailService;

/**
 * 订单详情Service业务层处理
 * 
 * @author liwenjing
 * @date 2021-05-15
 */
@Service
public class OrderDetailServiceImpl implements IOrderDetailService 
{
    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Autowired
    private LawyerTimeMapper lawyerTimeMapper;

    /**
     * 查询订单详情
     * 
     * @param id 订单详情ID
     * @return 订单详情
     */
    @Override
    public OrderDetail selectOrderDetailById(Long id)
    {
        return orderDetailMapper.selectOrderDetailById(id);
    }

    /**
     * 查询订单详情列表
     * 
     * @param orderDetail 订单详情
     * @return 订单详情
     */
    @Override
    public List<OrderDetail> selectOrderDetailList(OrderDetail orderDetail)
    {
        return orderDetailMapper.selectOrderDetailList(orderDetail);
    }

    /**
     * 新增订单详情
     * 
     * @param orderDetail 订单详情
     * @return 结果
     */
    @Override
    public int insertOrderDetail(OrderDetail orderDetail)
    {
        orderDetail.setCreateTime(DateUtils.getNowDate());
        return orderDetailMapper.insertOrderDetail(orderDetail);
    }

    /**
     * 修改订单详情
     * 
     * @param orderDetail 订单详情
     * @return 结果
     */
    @Override
    public int updateOrderDetail(OrderDetail orderDetail)
    {
        return orderDetailMapper.updateOrderDetail(orderDetail);
    }

    /**
     * 批量删除订单详情
     * 
     * @param ids 需要删除的订单详情ID
     * @return 结果
     */
    @Override
    public int deleteOrderDetailByIds(Long[] ids)
    {
        return orderDetailMapper.deleteOrderDetailByIds(ids);
    }

    /**
     * 删除订单详情信息
     * 
     * @param id 订单详情ID
     * @return 结果
     */
    @Override
    public int deleteOrderDetailById(Long id)
    {
        return orderDetailMapper.deleteOrderDetailById(id);
    }

    @Override
    public int updateOrderDetailByOrderId(OrderDetail orderDetail) {
        return orderDetailMapper.updateOrderDetailByOrderId(orderDetail);
    }

    @Override
    public OrderDetail selectServiceTimeByOrderId(String orderId) {
        return orderDetailMapper.selectServiceTimeByOrderId(orderId);
    }

    @Override
    public int ok(Long id) {
        return orderDetailMapper.ok(id);
    }

    @Override
    public int cancelOrderDetail(Long id) {
        return orderDetailMapper.cancelOrderDetail(id);
    }

    @Override
    public int greenOrderDetail(Long id) {
        OrderDetail orderDetail = orderDetailMapper.selectOrderDetailById(id);
        LawyerTime lawyerTime = new LawyerTime();
        lawyerTime.setLawyerCode(orderDetail.getLawyerCode());
        lawyerTime.setTimeDate(orderDetail.getServiceDate());
        String selectTime = lawyerTimeMapper.selectLawyerTimeByCode(lawyerTime);
        String time = orderDetail.getServiceTime();
        selectTime = selectTime.replace(time+",","");
        lawyerTime.setSelectTime(selectTime);
        lawyerTimeMapper.updateLawyerTimeByTime(lawyerTime);
        return orderDetailMapper.greenOrderDetail(id);
    }


}
